﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace Common.Behaviors
{
    public class FadeInOutAnimation : TargetedTriggerAction<FrameworkElement>
    {
        // properties
        public TimeSpan Time {get;set;} // how long must the animation take
        public enum Fade {FadeIn,FadeOut}; 
        public Fade FadeOptions {get;set;} // kind of animation
        
        // invoke method wil execute the behaviour
        protected override void Invoke(object parameter)
        {
            // get the element that must be animated
            FrameworkElement myElement = this.AssociatedObject as FrameworkElement;
           
            // check if we need to fade in or fade out
            double value;
            if(FadeOptions == Fade.FadeIn)value=1;else value = 0;

            // start the animation
            Animation.playAnimation(myElement.Name, "Opacity", this.Time, value);     
       }
    }
}
